import Axios from 'axios';
import { Toast } from 'vant';
export const baseURL = 'http://youchu.580travel.com'; //正式地址
// export const baseURL = 'http://qc.test.580travel.com'; //qc
// export const baseURL = 'http://192.168.1.10:94'; //俊贤

// export const baseURL = 'http://580.mynatapp.cc';
// export const baseURL = 'http://127.0.0.1:99';
// export const baseURL = 'http://192.168.1.51:88';
// export const baseURL = 'http://192.168.1.21:89'; // 俊贤
// export const baseURL = 'http://192.168.1.11:85'; // 杨帆
// export const baseURL = 'http://qa.test.580travel.com'; // qa 测试环境
// export const baseURL = 'http://qc.test.580travel.com'; // qc 测试环境
// export const baseURL = 'http://wjb.test.580travel.com';
// export const baseURL = 'http://youchuwjb.580travel.com';
// export const baseURL = 'http://youchuwjb.test.580travel.com';
// export const baseURL = 'http://192.168.1.123:81';
// export const baseURL = 'http://youchu.580travel.com';
// export const baseURL = 'http://580tour.natapp1.cc';
// export const baseURL = 'http://127.0.0.1:80';
// export const baseURL = 'http://192.168.1.9:83';
// export const baseURL = 'http://192.168.1.10:94';
// export const baseURL = 'http://192.168.1.11:94';
// export const baseURL = 'http://qc.test.580travel.com';
// export const baseURL = 'http://youchu.test.580travel.com';
// export const baseURL = 'http://tour.test.580travel.com';
// export const baseURL = 'http://youchu.580travel.com';
// export const baseURL = 'http://580tour.natapp1.cc';
// export const baseURL = 'http://580tour.natapp1.cc';
// export const baseURL = 'http://127.0.0.1:80';
// export const baseURL = 'http://192.168.1.9:83';
// export const baseURL = 'http://192.168.1.11:94';
// export const baseURL = 'http://youchu.test.580travel.com';
// export const baseURL = 'http://tour.test.580travel.com';
// export const baseURL = 'http://youchuwjb.580travel.com';
// export const baseURL = '';
// export const baseURL = 'http://fjefdw.natappfree.cc';
// export const baseURL = 'http://xmpsbcwjb.580travel.com'; // 正式地址
const Request = Axios.create({
  baseURL: baseURL,
  headers: {
    'Content-Type': 'application/json'
  }
});
const devUrl = baseURL;
Request.interceptors.request.use(
  function(config) {
    // console.log(toasts);
    Toast.loading({
      duration: 0, // 持续展示 toast
      forbidClick: true, // 禁用背景点击
      loadingType: 'spinner',
      message: '努力加载中'
    });
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);
Request.interceptors.response.use(
  response => {
    Toast.clear(true);
    return response;
  },
  error => {
    if (error && error.response) {
      switch (error.response.status) {
        case 400:
          error.message = '请求错误(400)';
          break;
        case 401:
          const str1 = devUrl + '/wx/toLogin?url=' + encodeURI(window.location);
          const str2 = devUrl + '/wx/accesscode?url=' + encodeURI(str1);
          window.location.href = str2;
          error.message = '重新登录';
          break;
        case 403:
          error.message = '拒绝访问(403)';
          break;
        case 404:
          error.message = '请求出错';
          break;
        case 408:
          error.message = '请求超时(408)';
          break;
        case 500:
          error.message = '服务器错误(500)';
          break;
        case 501:
          error.message = '服务未实现(501)';
          break;
        case 502:
          error.message = '网络错误(502)';
          break;
        case 503:
          error.message = '服务不可用(503)';
          break;
        case 504:
          error.message = '网络超时(504)';
          break;
        case 505:
          error.message = 'HTTP版本不受支持(505)';
          break;
        default:
          error.message = `连接出错(${error.response.status})!`;
      }
    }
    Toast.fail(error.message);
    return Promise.reject(error.response.data); // 返回接口返回的错误信息
  }
);

export default Request;
